package com.xlh.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.text.Html;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xlh.Utils.Constant;
import com.xlh.Utils.FUti;
import com.xlh.bean.TitleBean;
import com.xlh.bean.UserAttrBean;
import com.xlh.outside.R;
import com.xlh.view.roundcornerprogressbar.TextRoundCornerProgressBar;

import java.util.List;

public class UserAttrAdapter extends BaseAdapter {

	private List<UserAttrBean> data;
	private LayoutInflater mInflater;
	private boolean isCreated = false;

	public UserAttrAdapter(Context context, List<UserAttrBean> data) {
			// TODO Auto-generated constructor stub
			mInflater = LayoutInflater.from(context);
			this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data == null ? 0 : data.size();
	}
	public UserAttrBean getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}


 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder ;
		UserAttrBean userAttrBean = data.get(position);

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.user_attr_gr_item, parent, false);
			holder = new ViewHolder();
			holder.textProgressBar = (TextRoundCornerProgressBar) convertView.findViewById(R.id.TextRoundCornerProgressBar);
			holder.textProgressBar.setUpdateingClearTextProgressAlign(false);
			ViewGroup.LayoutParams  param = convertView.getLayoutParams();
			param.height = FUti.dip2px(convertView.getContext(), 20);
			convertView.setLayoutParams(param);
			convertView.setTag(holder);



		} else {
			holder = (ViewHolder) convertView.getTag();
		}




		holder.textProgressBar.setSecondaryProgressColor(Color.parseColor("#CCCCCC"));
		if(userAttrBean.getColor()!=null){
			//书剑代码没有设置颜色
			holder.textProgressBar.setProgressColor(Color.parseColor(userAttrBean.getColor()));
		}

		holder.textProgressBar.setTextProgressColor(Color.parseColor("#FFFFFF")) ;
		holder.textProgressBar.setRadius(1);
		holder.textProgressBar.setTextProgressSize(FUti.dip2px(convertView.getContext(), 10));


		holder.textProgressBar.setProgressText(String.format("%s.%d",userAttrBean.getText(),(int)userAttrBean.getIn()));
		holder.textProgressBar.setMax(userAttrBean.getMax());
		holder.textProgressBar.setProgress(userAttrBean.getIn());
		holder.textProgressBar.setSecondaryProgress(userAttrBean.getSpi());
		return convertView;
	}

	private class ViewHolder {
		
		private TextRoundCornerProgressBar textProgressBar;

		
	}
	
	public void addTitle(UserAttrBean bean) {
		// TODO Auto-generated method stub
		if (data != null) {
			data.add(bean);
		}
		this.notifyDataSetChanged();
	}

	public void setData(List<UserAttrBean> mTitleData) {
		// TODO Auto-generated method stub
		if(mTitleData != null) {
			this.data = mTitleData;
		}
		this.notifyDataSetChanged();
	}

	public void clear() {
		// TODO Auto-generated method stub
		if(data != null) {
			data.clear();
		}
		this.notifyDataSetChanged();
	}

	public void addTitle(List<UserAttrBean> ts) {
		// TODO Auto-generated method stub
		
		if(this.data != null) {
			
			for (int i = 0; i < ts.size(); i++) {
				this.data.add(ts.get(i));
			}
		}
		this.notifyDataSetChanged();
	}
	
}
